<template>
  <div class="disk-list">

    <mt-header fixed title="上级下发文件">
      <router-link :to="{name:'index'}" slot="left">
        <mt-button icon="back">返回</mt-button>
      </router-link>
    </mt-header>
    <div id="wrapper" ref="scrollWrap">
      <div class="scroller" ref="scroller">
        <a class="previous-link" v-if="isShowPrevious" @click="goPrevious">
          <i class="fa fa-arrow-circle-up"></i>
          返回上一级
        </a>
        <ul ref="scrollList" v-if="diskList.length > 0">
          <li v-for="disk in diskList" :key="disk.id" @click="handleLinkToFile(disk)">
            <disk-list-item :disk="disk" :from="'receiver'"></disk-list-item>
          </li>
        </ul>
        <empty-list v-else></empty-list>
      </div>
    </div>
  </div>
</template>
<script>
  import BScroll from 'better-scroll'
  import {getStyle,getDeviceRatio} from '../../base/js/util.js'
  import {api} from "../../base/js/api.js"
  import fetch from '../../utils/fetch'
  import DiskListItem from './DiskListItem'
  import { Indicator } from 'mint-ui';
  import EmptyList from '../Empty-List'
  /*获取当前缩放比*/
  const DEVICE_RATIO=getDeviceRatio();


  /**
   *
   * @param threshold 触发事件的阀值，即滑动多少距离触发
   * @param stop 下拉刷新后回滚
   */

  /*下拉配置*/
  const DOWN_CONFIG={
    threshold:20*DEVICE_RATIO,
    stop:20*DEVICE_RATIO
  }
  /*上拉配置*/
  const UP_CONFIG={
    threshold:-20*DEVICE_RATIO,
  }
  export default {
    data (){
      return{
        diskList:[],
        isShowPrevious: false,
        pdfurls: '//ozg66lgfl.bkt.clouddn.com/%E5%9E%83%E5%9C%BE.pdf',
        isshowpdf: false
      }
    },
    components:{
      DiskListItem,
      EmptyList
    },
    methods:{
      handleGetDiskList(parentPath){
        fetch('/api/disk/receiver/list').then(response =>{
          if(response.data.success) {
            this.diskList = response.data.obj
          }
          setTimeout(()=>{
            Indicator.close()
          }, 300)
        })
      },
      handleLinkToFile(disk) {
        if (disk.dirType === 0) {
          Indicator.open()
          this.isShowPrevious = true
          this.handleGetDiskList('/'+disk.name)
        } else {
          window.open('/api/disk/'+disk.id+'/pdf')
          this.isshowpdf = false
        }
      },
      goPrevious(){
        Indicator.open()
        this.handleGetDiskList('')
        this.isShowPrevious = false
      },
      closepdf(){
        this.isshowpdf = false
      },
      pdferr(errurl) {
        console.log(errurl);
      }
    },
    created(){
      Indicator.open()
      this.handleGetDiskList('')
    },
    mounted(){
      const {scroller,scrollWrap,scrollList}=this.$refs;
      this.scroller = new BScroll(scrollWrap,{
        click:true,
        probeType:3,
        pullDownRefresh:DOWN_CONFIG,
        pullUpLoad:UP_CONFIG
      });
    },
    deactivated () {
      this.$destroy()
    }
  }
</script>
<style scoped lang="scss">
  @import '../../base/css/_base';
  .disk-list{
    background: #F0EFF5;
    height: 100%;
  }
  #wrapper{
    position: fixed;
    top: 40px;
    bottom: 3px;
    width: 100%;
    overflow: hidden;
    background:#F0EFF5;
    z-index: 0;
    .scroller{
      position: absolute;
      width: 100%;
      &.topPadding{
        top:1rem;
      }
      .previous-link{
        display: inline-block;
        width: 100%;
        background: #fff;
        padding: 10px;
        @include fz(6px)
      }

    }
  }
  .cpdf{
    top: 40px;
    z-index: 10000;
  }
</style>
